import 'package:flutter/material.dart';
import 'package:flutter/animation.dart';

class AnimationTextWidget extends StatefulWidget {
  @override
  _AnimationTextWidget createState() {
    // TODO: implement createState
    return _AnimationTextWidget();
  }
}

class _AnimationTextWidget extends State<AnimationTextWidget>
    with SingleTickerProviderStateMixin {
  Animation<double> animation;
  AnimationController controller;

  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    controller = new AnimationController(
        vsync: this, duration: const Duration(milliseconds: 2000));
    animation = CurvedAnimation(parent: controller, curve: Curves.easeIn);

    animation = new Tween(begin: 0.0, end: 300.0).animate(animation)
      ..addListener(() {
        setState(() {
          print(animation.value);
        });
      });
    controller.forward();
  }

  startAnimation() {
    setState(() {
      controller.forward(from: 0);
    });
  }

  @override
  void dispose() {
    // TODO: implement dispose
    controller.dispose();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    // TODO: implement build
    return GestureDetector(
      onTap: () {
        startAnimation();
      },
      child: Center(
        child: Text(
          "落花人独立，微雨燕双飞",
          style: TextStyle(fontSize: 20 * controller.value),
        ),
      ),
    );
  }
}
